package com.ssy.lingxi.contract.repository;

import com.ssy.lingxi.contract.entity.PurchaseViePriceDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * 采购竞价合同
 * @author 伍将
 * @date 2021/3/15
 * @version 2.0.0
 */
public interface PurchaseViePriceRepository extends JpaRepository<PurchaseViePriceDO, Long>, JpaSpecificationExecutor<PurchaseViePriceDO> {

    /**
     * 查询采购竞价合同
     * @author 伍将
     * @date 2021/3/15
     * @param memberId: 竞价会员id
     * @param roleId: 竞价会员角色id
     * @param viePriceId: 竞价id
     * @param awardMemberId: 授标会员id
     * @param awardRoleId: 授标会员角色id
     * @return 采购竞价合同
     **/
    @Query(value = "select * from con_purchase_vie_price " +
            "where member_id =:memberId and role_id =:roleId " +
            "and vie_price_id =:viePriceId " +
            "and award_member_id =:awardMemberId and award_role_id =:awardRoleId " +
            "limit 1", nativeQuery = true)
    PurchaseViePriceDO findData(Long memberId, Long roleId, Long viePriceId, Long awardMemberId, Long awardRoleId);

    /**
     * 查询已被创建合同的采购竞价合同
     * @author 伍将
     * @date 2021/3/15
     * @param memberId: 竞价会员id
     * @param roleId: 竞价会员角色id
     * @param viePriceId: 竞价id
     * @param awardMemberId: 授标会员id
     * @param awardRoleId: 授标会员角色id
     * @return 采购竞价合同
     **/
    @Query(value = "select * from con_purchase_vie_price " +
            "where member_id =:memberId and role_id =:roleId " +
            "and vie_price_id =:viePriceId " +
            "and award_member_id =:awardMemberId and award_role_id =:awardRoleId " +
            "and is_create =1 " +
            "limit 1", nativeQuery = true)
    PurchaseViePriceDO findCreateData(Long memberId, Long roleId, Long viePriceId, Long awardMemberId, Long awardRoleId);
}
